using System;

namespace Slaks.Graphs.Algorithms.ExperimentalDistances
{
	public class WGUsubgraph
	{
		/// <summary>
		/// MCSsubgraph
		/// </summary>
		/// <param name="one"></param>
		/// <param name="two"></param>
		/// <returns></returns>
		public static double DistWGU4VertexEdgeCountSubgraph(Graph one, Graph two)
		{
			double mcsRegular = GraphDistances.DistWGU4VertexEdgeCount(one, two);

			Graph maxCommonSubgraph = (MaxCommonSubGraphVertexEdgeCount.GetMCS(one, two));
			double mcsVertexCount = maxCommonSubgraph.GetVertexCount();

			double graphSizeOneVertexCount = one.GetVertexCount();
			double graphSizeTwoVertexCount = two.GetVertexCount();

			double graphSizeOne = GraphDistances.GetGraphSizeVertexEdgeCount(one);
			double graphSizeTwo = GraphDistances.GetGraphSizeVertexEdgeCount(two);


			if (mcsVertexCount == graphSizeOneVertexCount)
			{
				return 1 - graphSizeOneVertexCount/graphSizeTwoVertexCount;
			}
			if (mcsVertexCount == graphSizeTwoVertexCount)
				return 1 - graphSizeTwoVertexCount/graphSizeOneVertexCount;
			if (mcsVertexCount*2 > graphSizeOneVertexCount && graphSizeOneVertexCount < graphSizeTwoVertexCount)
			{
				return 1 - graphSizeOne/Math.Max(graphSizeOne, graphSizeTwo);
			}
			else if (mcsVertexCount*2 > graphSizeTwoVertexCount && graphSizeOneVertexCount > graphSizeTwoVertexCount)
			{
				return 1 - graphSizeTwo/Math.Max(graphSizeOne, graphSizeTwo);
			}
			return mcsRegular;
		}

		public static double DistWGU4VertexEdgeFrequencySubgraph(Graph one, Graph two)
		{
			double mcsRegular = GraphDistances.DistWGU4VertexEdgeFrequency(one, two);

			Graph maxCommonSubgraph = (MaxCommonSubGraphVertexEdgeFrequency.GetMCS(one, two));
			double mcsEdgeFrequency = maxCommonSubgraph.GetEdgeFrequency();
			double mcsVertexFrequency = maxCommonSubgraph.GetVertexFrequency();

			//double graphSizeOneEdgeCount = one.GetEdgeCount();
			double graphSizeOneVertexFrequency = one.GetVertexFrequency();
			//double graphSizeTwoEdgeCount = two.GetEdgeCount();
			double graphSizeTwoVertexFrequency = two.GetVertexFrequency();

			double graphSizeOne = GraphDistances.GetGraphSizeVertexEdgeFrequency(one);
			double graphSizeTwo = GraphDistances.GetGraphSizeVertexEdgeFrequency(two);


			if (mcsVertexFrequency == graphSizeOneVertexFrequency)
				return graphSizeOneVertexFrequency/graphSizeTwoVertexFrequency;
			if (mcsVertexFrequency == graphSizeTwoVertexFrequency)
				return graphSizeTwoVertexFrequency/graphSizeOneVertexFrequency;
			if (mcsVertexFrequency*2 > graphSizeOneVertexFrequency && graphSizeOneVertexFrequency < graphSizeTwoVertexFrequency)
			{
				//return 1 - graphSizeOneVertexCount /Math.Max(graphSizeOne, graphSizeTwo);
				return 1 - graphSizeOne/Math.Max(graphSizeOne, graphSizeTwo);
				//return 1 - graphSizeOneVertexCount / graphSizeTwoVertexCount;
			}
			else if (mcsVertexFrequency*2 > graphSizeTwoVertexFrequency && graphSizeOneVertexFrequency > graphSizeTwoVertexFrequency)
			{
				//return 1 - graphSizeTwoVertexCount /Math.Max(graphSizeOne, graphSizeTwo);
				return 1 - graphSizeTwo/Math.Max(graphSizeOne, graphSizeTwo);
				//return 1 - graphSizeTwoVertexCount / graphSizeOneVertexCount;
			}
			return mcsRegular;
		}


	}
}